        package com.by.yz.loginUtil;
        import android.content.Context;
        import com.android.volley.AuthFailureError;
        import com.android.volley.Request;
        import com.android.volley.Response;
        import com.android.volley.VolleyError;
        import com.android.volley.toolbox.JsonArrayRequest;
        import com.android.volley.toolbox.Volley;
        import org.json.JSONArray;
        import java.util.HashMap;
        import java.util.Map;

/**
 * Created by Abe on 2016/10/8.
 */
public class codeRESTFul {
    public interface IgetCodeCb{
        public void ok(JSONArray response);
        public  void error(String error);
    }
    public void getCode(final Context context, final String phone, final IgetCodeCb cb) {



        String url = Constants.server_url + "/api/account/code/"+phone;
        JsonArrayRequest postRequest = new JsonArrayRequest(Request.Method.GET, url,null,
                new Response.Listener<JSONArray>() {
                    @Override
                    public void onResponse(JSONArray response) {
                        cb.ok(response);
                    }
                },
                new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError error) {
                        error.printStackTrace();
                        cb.error(error.toString());
                    }
                }
        ){
            @Override
            public Map<String, String> getHeaders() throws AuthFailureError {
                HashMap<String, String> headers = new HashMap<String, String>();
                //headers.putAll(Constants.getCookie());
                headers.put("Content-Type", "application/x-www-form-urlencoded; charset=utf-8");
                headers.put("X-XSRF-TOKEN",Constants.getCSRF());
                return headers;
            }
        };

        Volley.newRequestQueue(context).add(postRequest);
    }
}

